from django import forms
from .models import Asset, WorkflowTemplate

class AssetBorrowRequestForm(forms.Form):
    asset = forms.ModelChoiceField(
        queryset=Asset.objects.filter(status__in=['idle', 'in_use']),
        label="选择资产",
        widget=forms.Select(attrs={'class': 'form-control'})
    )
    reason = forms.CharField(
        label="借用事由",
        widget=forms.Textarea(attrs={'class': 'form-control', 'rows': 3})
    )

class WorkflowTemplateForm(forms.ModelForm):
    class Meta:
        model = WorkflowTemplate
        fields = ['name', 'template_type', 'description', 'workflow_definition', 'is_active']
        widgets = {
            'name': forms.TextInput(attrs={'class': 'form-control'}),
            'template_type': forms.Select(attrs={'class': 'form-select'}),
            'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
            'workflow_definition': forms.Textarea(attrs={'class': 'form-control', 'rows': 15}),
            'is_active': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
        }

class AssetScrapRequestForm(forms.Form):
    reason = forms.CharField(
        label="报废事由",
        widget=forms.Textarea(attrs={'class': 'form-control', 'rows': 3})
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['asset'].empty_label = "请选择一个资产"